function jump(nums: number[]): number {
  let now = 0;
  let ans = 0;
  while (now < nums.length - 1) {
    let right = now + nums[now];
    if (right >= nums.length - 1) return ans + 1;
    let nextRight = right;
    let next = now;
    for (let i = now + 1; i <= right; i++) {
      if (i + nums[i] > nextRight) {
        nextRight = i + nums[i];
        next = i;
      }
    }
    now = next;
    ans++;
  }
  return ans;
};